<?php

class LinkModel extends AppModel 
{
	public function __construct()
	{
		$this->table = '@#_link';
		parent::__construct();
	}
	
	public function getCateList()
	{
		return $this->db->getAll("SELECT * FROM @#_cate");
	}
	
	public function addCate($data)
	{
		return $this->add($data, '@#_cate');
	}
	
	public function addSubCate($data)
	{
		if($this->isExists("name='{$data['name']}' AND cate_id={$data['cate_id']}", "@#_subcate")){
			$this->msg = "分类 {$data['name']} 已经存在";
			return false;
		}
		return $this->add($data, '@#_subcate');
	}
	
	public function getSubCateList($cateId)
	{
		return $this->db->getAll("SELECT sub.id, sub.name, @#_cate.name AS pcate_name, sub.created, sub.updated
								  FROM @#_subcate AS sub
								  LEFT JOIN @#_cate 
								  ON(sub.cate_id=@#_cate.id) 
								  WHERE sub.cate_id=$cateId");
	}
}